﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using PokerServerWebService.BusinessEntities;
using PokerServerWebService.DataAccess.Generic;
using System.Globalization;

namespace PokerServerWebService.DataAccess
{
    /// <summary>
    /// This factory class takes a CASINO_USER_MONEY object and generates
    /// the dbcommand object needed to call the underlying update
    /// stored proc.
    /// </summary>
    internal class CASINO_USER_MONEYUpdateFactory : IDbToBusinessEntityNameMapper, IUpdateFactory<CASINO_USER_MONEY>
    {
        /// <summary>
        /// Creates the CASINO_USER_MONEYUpdateFactory to build an update statement for
        /// the given CASINO_USER_MONEY object.
        /// </summary>
        /// <param name="CASINO_USER_MONEY">CASINO_USER_MONEY to update into the database.</param>
        public CASINO_USER_MONEYUpdateFactory()
        {
        }

        #region IUpdateFactory<CASINO_USER_MONEY> Members

        public DbCommand ConstructUpdateCommand(Database db, CASINO_USER_MONEY cASINO_USER_MONEY)
        {
            DbCommand command = db.GetStoredProcCommand("dbo.UpdatePlayerMoney");

            db.AddInParameter(command, "id", DbType.Int32, cASINO_USER_MONEY.User_ID);
            db.AddInParameter(command, "money", DbType.Int32, cASINO_USER_MONEY.User_Money);
            return command;
        }
        #endregion

        #region IDbToBusinessEntityNameMapper Members
        /// <summary>
        /// Maps a field name in the database (usually a parameter name for a stored proc)
        /// to the corresponding business entity property name.
        /// </summary>
        /// <remarks>This method is intended for error message handling, not for reflection.</remarks>
        /// <param name="dbParameter">Name of field/parameter that the database knows about.</param>
        /// <returns>Corresponding business entity field name.</returns>
        public string MapDbParameterToBusinessEntityProperty(string dbParameter)
        {
            switch (dbParameter)
            {
                case "id":
                    return "User_ID";
                case "money":
                    return "User_Money";
                default:
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GenericResources.InvalidParameterName), dbParameter);
            }
        }
        #endregion
    }
}

